import { Button, Divider, Input, message } from 'antd';
import { GTable } from 'geminis-react';
import styles from './scan.less';
import { useRef, useState } from 'react';
// import request from 'umi-request';

export const Scan = (props: any) => {
  const [productNo, setProductNo] = useState<string>();
  const tableRef = useRef<any>();

  const scan = () => {
    // request(
    //   '/api/warehouse/purchase/detail/scan/' + props.orderId + '/' + productNo,
    //   {
    //     method: 'post',
    //   },
    // )
    //   .then(() => {
    //     tableRef.current.loadData();
    //   })
    //   .catch((err) => {
    //     message.error(err.data.message);
    //   });
  };

  return (
    <>
      <span className={styles.scan}>
        货物条码：
        <Input
          value={productNo}
          onChange={(e) => {
            setProductNo(e.target.value);
          }}
        />
        <Button disabled={!productNo || productNo.length === 0} onClick={scan}>
          扫码
        </Button>
      </span>
      <Divider></Divider>
      <GTable
        ref={tableRef}
        schema={{
          data: {
            url: '/api/warehouse/purchase/detail',
            filter: {
              filters: [
                {
                  field: 'purchase.id',
                  compareType: '=',
                  value: props.orderId,
                },
              ],
            },
          },
        }}
        schemaPath="/warehouse-pc/schemas/purchase/receive/scan-table.json"
      />
    </>
  );
};
